const userTable = require('@/tables/system/user');
module.exports = {
	/**
	 * 获取用户列表
	 * @param {Object} params 
	 */
	async getUserList(params) {
		const { page, pageSize } = params;
		const offset = (page - 1) * pageSize;
		const limit = pageSize;
		const result = await userTable.findAndCountAll({
			offset,
			limit,
			where: {
				...params
			}
		});
		return result;
	},
	/**
	 * 获取用户信息
	 * @param {Object} params 
	 */
	async getUserInfo(params) {
		const result = await userTable.findOne({
			where: {
				...params
			}
		});
		return result;
	},
	/**
	 * 新增用户		
	 * @param {Object} params 
	 */
	async createUser(params) {
		const result = await userTable.create(params);
		return result;
	},
	/**
	 * 更新用户信息
	 * @param {Object} params 
	 */
	async updateUser(params) {
		const result = await userTable.update(params, {
			where: {
				id: params.id
			}
		});
		return result;
	},
	/**
	 * 删除用户
	 * @param {Object} params 
	 */
	async deleteUser(params) {
		const result = await userTable.destroy({
			where: {
				id: params.id
			}
		});
		return result;
	}
}